Skip to main content

Visible, Editable, and Required Using Expression

This article presents examples on how to use an expression to set the basic properties of a control. These properties include whether controls are visible, required, or editable.


Example Scenario

Suppose a Transportation and Logistics company has defined a process called Shipping Process, to manage and monitor international shipments. The first task of this process allows the customers to enter the information and estimate the cost of the shipment.

  • The company provides shipping services between Brazil, Ireland, and the United States.
  • Transportation of goods can be by air, land, or sea.
  • If the selected means of transport is air, an express service is offered for same-day shipping and delivery.

Data Capture Form Requirements

  1. Zip Code Control

    • Editable and required if the destination country is Brazil or the USA.
    • Read-only if the destination country is other than Brazil or the USA.
  2. Express Service Option

    • Visible only when the means of transport is air.

Configuring Editability

Since the Zip Code only applies to Brazil and the USA, the Editable property of the Zip Code control will be evaluated once the country is selected. The steps to configure this are:

Steps:

  1. In the Form, click the Zip Code control to enable its Properties in the panel on the left.
    Step 1

  2. Locate the Editable property in the Basic tab. Expand the drop-down list to view the available options.
    Step 2

  3. Select the last option: Expression. A new window will display.
    To create a new expression, click New.
    Step 3

  4. Configure the required conditions. In this case, the condition relates to the destination country attribute.
    Step 4

    • A Boolean expression returns TRUE or FALSE.
      • If TRUE (destination country is Brazil or USA), the control is editable.
      • Otherwise, the control is not editable.
  5. To evaluate the expression, refresh the Zip Code control when a Country is selected. Create an action and use the Refresh command to do so.
    Step 5

  6. In the Work Portal:

    • Select Ireland as the destination country. The Zip Code control is read-only.
      Step 6.1
    • Select Brazil or the USA as the destination country. The Zip Code control is editable.
      Step 6.2

Configuring a Mandatory Control

Using the same example, if the package is dutiable (taxes apply), the Declared Value must be entered. To ensure this, make it Required.

Steps:

  1. On the form, click the Declared Value control. Its properties will display in the left panel.
    Step 1

  2. In the Basic Properties tab, find the Required behavior. Expand the drop-down list.
    Step 2

  3. Select the last option: Expression. Click New to create a new expression.
    Step 3

  4. Add a condition where the Dutiable Material control value is TRUE.
    Step 4

  5. Refresh the Declared Value control when the Dutiable Material control value changes.
    Step 5


Showing or Hiding a Control

To ensure the Express Service control only appears for air transportation, configure its visibility as follows:

Steps:

  1. In the Form, click the Express Service control to show its properties in the left panel.
    Step 1

  2. In the Basic Properties tab, find the Visible behavior. Expand the drop-down list.
    Step 2

  3. Select Expression and create a new expression.
    Step 3

  4. Add a condition where the Transportation Means is equal to Air.
    Step 4

  5. Refresh the Express Service control when the Transportation Means value changes.
    Step 5

    • In the Work Portal:
      • Select Air as the transportation means. The Express Service control appears.
        Air Selected
      • Select another transportation means. The Express Service control is hidden.
        Other Selected

Using Scripting Expressions for Complex Conditions

For complex visibility conditions, such as specific origin-destination routes, scripting expressions are required.

Example: Express Service for Specific Air Routes

The following table shows applicable routes:

OriginDestinationExpress Service Applies?
BrazilIrelandNo
BrazilUSAYes
USAIrelandYes
USABrazilYes
IrelandUSANo
IrelandBrazilNo

To implement this:

  1. In the Form, click the Express Service control to display its properties in the left panel.
    Step 1

  2. Expand the Visible behavior drop-down list.
    Step 2

  3. Select Expression to display the Expression Manager.

  4. The Expression selection window will open to select the rule (if it was already created) or to create a new rule.

Expression Selection Window


  1. Expand the New options and select Scripting.

Expand New Options


  1. Right click on the vertical line of the rule and add an expression.

Add Expression


  1. This expression calls for certain Constant definitions to be previously defined in the vocabulary, by which to reference specified entities values.

These definitions will contain the internal identifier, which is an attribute of the entity, of the specific country or transportation means.

Vocabulary Definitions


  1. Type the following code and save the expression:

Code Example

//Set false if no condition is fulfilled.
var result = false;

//Obtain code of air transportation from vocabulary
var AirCode = CHelper.resolveVocabulary(Me, "Air");

//Obtain code of Brazil from vocabulary
var BrazilCode = CHelper.resolveVocabulary(Me, "Brazil");

//Obtain code of USA from vocabulary
var USACode = CHelper.resolveVocabulary(Me, "USA");

//Obtain code of Ireland from vocabulary
var IrelandCode = CHelper.resolveVocabulary(Me, "Ireland");

//Evaluate if the transportation means is air.
if (<Shipping.TransportationMean.Code> == AirCode) {
//Evaluate if shipment route is Brazil-USA.
if (<Shipping.CountryFrom.Code> == BrazilCode && <Shipping.CountryTo.Code> == USACode) {
//Set true
result = true;
}
//Evaluate if shipment route is USA-Ireland.
if (<Shipping.CountryFrom.Code> == USACode && <Shipping.CountryTo.Code> == IrelandCode) {
//Set true
result = true;
}
//Evaluate if shipment route is USA-Brazil.
if (<Shipping.CountryFrom.Code> == USACode && <Shipping.CountryTo.Code> == BrazilCode) {
//Set true
result = true;
}
}

//Return the result
result;

  1. It is necessary to evaluate this property each time the value of the transportation means, country of origin, and country of destination changes.

Create and action and use the refresh command to do so.

Test the property in the Work Portal.

Select an origin-destination route that offers an express service and then select Air as the transportation means.

Note the Express Service control is shown in the Service Information group for selection.

Now select an origin-destination route that does not offer an express service and again select Air as the transportation means. This time the Express Service control remains hidden.

Note:

When you define behaviors over the columns of a table, they will apply to the entire column, regardless of its visibility, given that the columns are included in the metadata of the project.

If you wish to know how to configure visibility and editability over the cells of a table, please refer to Configuring cells visibility and editability.